package com.ruoyi.base.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.base.domain.FinancialDefaultAccount;
import com.ruoyi.base.service.IFinancialDefaultAccountService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 默认账套Controller
 * 
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/defaultAccount")
public class FinancialDefaultAccountController extends BaseController
{
    @Autowired
    private IFinancialDefaultAccountService financialDefaultAccountService;

    /**
     * 查询默认账套列表
     */
    @RequiresPermissions("base:defaultAccount:list")
    @GetMapping("/list")
    public TableDataInfo list(FinancialDefaultAccount financialDefaultAccount)
    {
        startPage();
        List<FinancialDefaultAccount> list = financialDefaultAccountService.selectFinancialDefaultAccountList(financialDefaultAccount);
        return getDataTable(list);
    }

    @GetMapping("/getAccountId")
    public Long getAccountId(){
        return financialDefaultAccountService.getAccountId();
    }

    /**
     * 导出默认账套列表
     */
    @RequiresPermissions("base:defaultAccount:export")
    @Log(title = "默认账套", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinancialDefaultAccount financialDefaultAccount)
    {
        List<FinancialDefaultAccount> list = financialDefaultAccountService.selectFinancialDefaultAccountList(financialDefaultAccount);
        ExcelUtil<FinancialDefaultAccount> util = new ExcelUtil<FinancialDefaultAccount>(FinancialDefaultAccount.class);
        util.exportExcel(response, list, "默认账套数据");
    }

    /**
     * 获取默认账套详细信息
     */
    @RequiresPermissions("base:defaultAccount:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(financialDefaultAccountService.selectFinancialDefaultAccountById(id));
    }

    /**
     * 新增默认账套
     */
    @RequiresPermissions("base:defaultAccount:add")
    @Log(title = "默认账套", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinancialDefaultAccount financialDefaultAccount)
    {
        return toAjax(financialDefaultAccountService.insertFinancialDefaultAccount(financialDefaultAccount));
    }

    /**
     * 修改默认账套
     */
    @RequiresPermissions("base:defaultAccount:edit")
    @Log(title = "默认账套", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinancialDefaultAccount financialDefaultAccount)
    {
        return toAjax(financialDefaultAccountService.updateFinancialDefaultAccount(financialDefaultAccount));
    }

    /**
     * 删除默认账套
     */
    @RequiresPermissions("base:defaultAccount:remove")
    @Log(title = "默认账套", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(financialDefaultAccountService.deleteFinancialDefaultAccountByIds(ids));
    }
}
